import {
  Reducers,
  ModelOptions
} from './types';

import model from './model';

import config from './../../config';

import * as effects from './effects';

const globalState: any = {
  author: 'J.T',
  version: `dva_${config.version}`
};

const reducers: Reducers = {
  globalReducer: (state = globalState) => state
}

export default <State = any>(opts?: ModelOptions) => {
  if (opts) reducers[opts?.namespace] = model<State>(opts);
  if (opts?.effects) effects.set(opts?.namespace, opts?.effects);
  return reducers;
}


